﻿using netDxf;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestDxfDocument

{
    class ISYC_302_04
    {
        //GB/Z 29014.3 ISYC 302-04-整体圆柱柄平底锪钻
        public static void ISYC_302_04_j(Dictionary<string, Object> data)  //整体圆柱柄阶梯式锥面锪钻
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            /* double scale = 3;
             double pi = Math.PI;
             string path = Convert.ToString(data["path"]);
             double dc = 30;
             double dcintf = 18;
             double dconms = 24.5;
             double lcf = 34.277;
             double ls = 75.89;
             double oal = 34.277 * 5;
             double dn = 20;
             double fha = 10;
             double fha_ = fha * pi / 180;
            */
            
            double scale = 3;
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);
            double dc = Convert.ToDouble(data["dc"]);
            double dcintf = Convert.ToDouble(data["dcintf"]);
            double dconms = Convert.ToDouble(data["dconms"]);
            double lcf = Convert.ToDouble(data["lcf"]);
            double ls = Convert.ToDouble(data["ls"]);
            double oal = Convert.ToDouble(data["oal"]);
            double dn = Convert.ToDouble(data["dn"]);
            double fha = Convert.ToDouble(data["fha"]);
            double fha_ = fha * pi / 180;
            
            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0_1 = new Vector2(-5, 0);
            Vector2 p0_2 = new Vector2(oal + 5, 0);
            Vector2 p1 = fun.Polar(p0, pi / 2, dc / 10.0 / 2.0);
            Vector2 p2 = fun.Polar(p0, pi / -2, dc / 10.0 / 2.0);
            Vector2 p3 = fun.Polar(p1, pi / 2, (dcintf - (dc / 10.0)) / 2.0 / 2.0);
            Vector2 p4 = fun.Polar(p3, fha_, lcf / Math.Cos(fha_) + 0.1);
            Vector2 p5 = fun.mirrorpoint(p3, p0_1, p0_2);
            Vector2 p6 = fun.Polar(p4, pi / -2 - 0.01 * pi / 180, oal);
            Vector2 p7 = fun.Polar(p1, fha_, lcf / Math.Cos(fha_) - (dcintf - (dc / 10.0)) / 2.0 / 2.0);
            Vector2 p8 = fun.Polar(p1, pi / 2, (dcintf - (dc / 10.0)) / 2.0);
            Vector2 p9 = fun.Polar(p8, fha_, lcf / Math.Cos(fha_) - (dcintf - (dc / 10.0)) / 2.0 / 2.0);
            /* System.Diagnostics.Debug.WriteLine((lcf-(dcintf -dc/10)/4.0) / Math.Cos(fha));
             System.Diagnostics.Debug.WriteLine((lcf - (dcintf - dc / 10) / 4.0));*/

            Vector2 p10 = fun.Polar(p7, pi / -2, dc / 10);
            Vector2 p11 = fun.mirrorpoint(p8, p0_1, p0_2);
            Vector2 p12 = fun.Polar(p11, fha_, lcf / Math.Cos(fha_) - (dcintf - (dc / 10.0)) / 2.0 / 2.0);
            Vector2 p13 = fun.Polar(p11, pi / -2, dc / 10.0);
            Vector2 p14 = fun.Polar(p12, pi / -2, dc / 10.0);
            Vector2 p15_ = fun.Polar(p0, pi / -2, dc / 2.0);
            Vector2 p15 = fun.Polar(p15_, 0, lcf / 20.0);
            Vector2 p16_1 = fun.Polar(p15, 0, oal);
            Vector2 p16_2 = fun.Polar(p14, pi / -2, oal);
            Vector2 p16 = fun.Inters(p15, p16_1, p14, p16_2);
            Vector2 p17 = fun.Polar(p8, pi / 2, dc / 10.0);
            Vector2 p18 = fun.Polar(p9, pi / 2, dc / 10.0);
            Vector2 p19 = fun.Polar(p18, pi, lcf / Math.Cos(fha_) - (dcintf - (dc / 10.0)) / 2.0 / 2.0 - lcf / 15.0);
            Vector2 p20 = fun.Polar(p16, pi / 6, (dc - dn));
            Vector2 p21 = fun.Polar(p18, pi / -6, (dc - dn));
            Vector2 p19_ = fun.Polar(p19, pi / -2, oal);
            Vector2 p22 = fun.Inters(p8, p9, p19, p19_);
            Vector2 p23 = fun.Inters(p2, p10, p19, p19_);
            Vector2 p22_1 = fun.Polar(p19, 0, 0.1);
            Vector2 p22_2 = fun.Polar(p22_1, pi / -2 + 0.1 * pi / 180, oal);
            Vector2 p15_1 = fun.Polar(p15, 0, 0.1);
            Vector2 p15_2 = fun.Polar(p15_1, pi / 2 + 0.1 * pi / 180, oal);
            Vector2 p24_1 = fun.Polar(p3, fha_, lcf / Math.Cos(fha_));
            Vector2 p24_2 = fun.Polar(p24_1, pi / -2, oal);
            Vector2 p24 = fun.Inters(p16, p20, p24_1, p24_2);
            Line line1 = new Line(p22_1, p22_2);
            Line line2 = new Line(p15_1, p15_2);
            Line line3 = new Line(p4, p6);
            Vector2 p25 = fun.Polar(p20, 0, p21.X * 2);
            Vector2 p26 = fun.Polar(p21, 0, p21.X * 2);
            Vector2 p25_1 = fun.Polar(p25, pi / 2, fun.CalDistance(p25, p26) / 2.0);
            Vector2 p25_2 = fun.Polar(p25_1, 0, oal);
            Vector2 p27 = fun.Polar(p25, pi / -4, (dconms - dn) / 2.0 * Math.Sqrt(2));
            Vector2 p28 = fun.mirrorpoint(p27, p25_1, p25_2);
            Vector2 p29 = fun.Polar(p27, 0, ls - (dconms - dn) / 2.0 * Math.Sqrt(2));
            Vector2 p30 = fun.mirrorpoint(p29, p25_1, p25_2);
            Vector2 p31 = fun.Polar(p29, pi / 4, (dconms - dn) / 2.0 * Math.Sqrt(2));
            Vector2 p32 = fun.mirrorpoint(p31, p25_1, p25_2);
            Vector2 p33 = fun.Polar(p0, pi, oal / 2.0);
            Vector2 p34 = fun.Polar(p33, pi / 2, dconms / 2.0);
            Vector2 p35 = fun.Polar(p34, pi, dconms);
            Vector2 p36 = fun.Polar(p35, pi / 2, dconms / 2.0);
            Vector2 p37 = fun.Polar(p36, -15 * pi / 180, dconms / 5.0 / Math.Cos(-15 * pi / 180));
            Vector2 p38 = fun.Polar(p37, 15 * pi / 180, dconms / 5.0 / Math.Cos(-15 * pi / 180));
            Vector2 p39 = fun.Polar(p38, -15 * pi / 180, dconms / 5.0 / Math.Cos(-15 * pi / 180));
            Vector2 p40 = fun.Polar(p39, 15 * pi / 180, dconms / 5.0 / Math.Cos(-15 * pi / 180));
            Vector2 p41 = fun.Polar(p40, -15 * pi / 180, dconms / 5.0 / Math.Cos(-15 * pi / 180));
            Vector2 p42 = fun.mirrorpoint(p34, p0_1, p0_2);
            Vector2 p43 = fun.mirrorpoint(p35, p0_1, p0_2);
            Vector2 p44 = fun.mirrorpoint(p36, p0_1, p0_2);
            Vector2 p45 = fun.mirrorpoint(p37, p0_1, p0_2);
            Vector2 p46 = fun.mirrorpoint(p38, p0_1, p0_2);
            Vector2 p47 = fun.mirrorpoint(p39, p0_1, p0_2);
            Vector2 p48 = fun.mirrorpoint(p40, p0_1, p0_2);
            Vector2 p49 = fun.mirrorpoint(p41, p0_1, p0_2);


            Arc arc1 = fun.DrawArc5(p17, line1, p19);
            Arc arc2 = fun.DrawArc5(p1, line1, p22);
            Arc arc3 = fun.DrawArc5(p11, line1, p23);
            Arc arc4 = fun.DrawArc5(p15, line2, p13);
            Arc arc5 = fun.DrawArc5(p7, line3, p9);
            Arc arc6 = fun.DrawArc5(p12, line3, p10);
            Arc arc7 = fun.DrawArc5(p24, line3, p14);
            var polyline1 = Pus.AddPointsToLwPolyLine(p19, p18, p17, p8, p9, p18, p21, p20, p16, p15);
            var polyline2 = Pus.AddPointsToLwPolyLine(p11, p13, p14, p12, p11);
            var polyline3 = Pus.AddPointsToLwPolyLine(p1, p2, p10, p7, p1);
            var polyline4 = Pus.AddPointsToLwPolyLine(p20, p25, p26, p28, p27, p25, p27, p29, p30, p32, p31, p29, p30, p28, p26, p21); ;
            var polyline5 = Pus.AddPointsToLwPolyLine(p34, p35, p36, p37, p38, p39, p40, p41, p34);
            var polyline6 = Pus.AddPointsToLwPolyLine(p42, p43, p44, p45, p46, p47, p48, p49, p42);
            fun.drawBArc(dxf, arc1, 0.5, contour);
            fun.drawBArc(dxf, arc2, 0.5, contour);
            fun.drawBArc(dxf, arc3, 0.5, contour);
            fun.drawBArc(dxf, arc4, 0.5, contour);
            fun.drawBArc(dxf, arc5, 0.5, contour);
            fun.drawBArc(dxf, arc6, 0.5, contour);
            fun.drawBArc(dxf, arc7, 0.5, contour);
            fun.PolyFill(dxf, polyline1, 0.5, contour);
            fun.PolyFill(dxf, polyline2, 0.5, contour);
            fun.PolyFill(dxf, polyline3, 0.5, contour);
            fun.PolyFill(dxf, polyline4, 0.5, contour);
            fun.PolyFill(dxf, polyline5, 0.5, contour);
            fun.PolyFill(dxf, polyline6, 0.5, contour);

            //标注
            Vector2 v1 = fun.Polar(p32, pi / -2, p32.Y);
            Vector2 v2 = fun.Polar(p26, pi, ls / 8.0);
            Vector2 v3 = fun.Polar(v1, pi, ls / 2.0);
            Vector2 v4 = fun.Polar(p19, pi / 2 + 20 * pi / 180, dcintf * 3.5);

            Vector2 v5 = fun.Polar(p0, pi + pi / 4, 1.7 * 0.3 * scale);
            Vector2 v6 = fun.Polar(v5, pi + pi / 4, dcintf * 1.5);
            Vector2 v7 = fun.Polar(v6, pi / -2, 1.2 * scale);

            Vector2 v8 = fun.Polar(p13, pi / -2, -(p15.Y - p13.Y));

            Vector2 v9 = fun.Polar(v8, pi / -4, 1.7 * 0.3 * scale);
            Vector2 v10 = fun.Polar(v9, pi / -4, dcintf / 2.0);
            Vector2 v11 = fun.Polar(v10, pi / -2, 1.2 * scale);

            Vector2 v12 = fun.Polar(v3, pi + pi / 3, 1.7 * 0.3 * scale);
            Vector2 v13 = fun.Polar(v12, pi + pi / 3, dconms);
            Vector2 v14 = fun.Polar(v13, pi / -2, 1.2 * scale);

            Vector2 v15 = fun.Polar(v1, pi / -4, 1.7 * 0.3 * scale);
            Vector2 v16 = fun.Polar(v15, pi / -4, dconms);
            Vector2 v17 = fun.Polar(v16, pi / -2, 1.2 * scale);

            Vector2 v18 = fun.Polar(v3, pi / 2, dconms);
            Vector2 v19 = fun.Polar(v18, pi / 4, dconms / 4.0);
            Vector2 v20 = fun.Polar(v19, 0, dconms / 2.0);
            Vector2 v21 = fun.mirrorpoint(v18, fun.Polar(v3, 0, oal), v3);
            Vector2 v22 = fun.mirrorpoint(v19, fun.Polar(v3, 0, oal), v3);
            Vector2 v23 = fun.mirrorpoint(v20, fun.Polar(v3, 0, oal), v3);
            Vector2 v24 = fun.Polar(p11, pi / -2, dcintf);
            Line linev5 = new Line(v18, v21);
            Line linev6 = new Line(v18, v19);
            Line linev7 = new Line(v19, v20);
            Line linev8 = new Line(v21, v22);
            Line linev9 = new Line(v22, v23);
            linev5.Lineweight = Lineweight.W35;//Lineweight指线宽
            linev5.Layer = additionalline;//Layer指图层
            linev5.LinetypeScale = 5 / scale * 1.5;//指线性比例
            linev5.Linetype = Linetype.DashDot;//Linetype指是点划线还是虚线什么的
            dxf.AddEntity(linev5); //提取
            linev6.Lineweight = Lineweight.W35;//Lineweight指线宽
            linev6.Layer = additionalline;//Layer指图层
            linev6.LinetypeScale = 5 / scale * 1.5;//指线性比例
            linev6.Linetype = Linetype.DashDot;//Linetype指是点划线还是虚线什么的
            dxf.AddEntity(linev6); //提取
            linev7.Lineweight = Lineweight.W35;//Lineweight指线宽
            linev7.Layer = additionalline;//Layer指图层
            linev7.LinetypeScale = 5 / scale * 1.5;//指线性比例
            linev7.Linetype = Linetype.DashDot;//Linetype指是点划线还是虚线什么的
            dxf.AddEntity(linev7); //提取
            linev8.Lineweight = Lineweight.W35;//Lineweight指线宽
            linev8.Layer = additionalline;//Layer指图层
            linev8.LinetypeScale = 5 / scale * 1.5;//指线性比例
            linev8.Linetype = Linetype.DashDot;//Linetype指是点划线还是虚线什么的
            dxf.AddEntity(linev8); //提取
            linev9.Lineweight = Lineweight.W35;//Lineweight指线宽
            linev9.Layer = additionalline;//Layer指图层
            linev9.LinetypeScale = 5 / scale * 1.5;//指线性比例
            linev9.Linetype = Linetype.DashDot;//Linetype指是点划线还是虚线什么的
            dxf.AddEntity(linev9); //提取

            Line linev10 = new Line(p0_1, p0_2);
            linev10.Lineweight = Lineweight.W25;//Lineweight指线宽
            linev10.Layer = additionalline;//Layer指图层
            linev10.LinetypeScale = 5 / scale * 1.5;//指线性比例
            linev10.Linetype = Linetype.DashDot;//Linetype指是点划线还是虚线什么的
            dxf.AddEntity(linev10); //提取

            fun.dimrot1(dxf, p0, p4, 0, dcintf * 1.5, 2, 1.2 * scale, 1.6 * scale, 0.9, "LCF", "", "");
            fun.dimrot1(dxf, p0, v2, 0, dcintf * 2.5, 2, 1.2 * scale, 1.6 * scale, 0.9, "LU", "", "");
            fun.dimrot1(dxf, p0, v3, 0, dcintf * 3.3, 2, 1.2 * scale, 1.6 * scale, 0.9, "LPR", "", "");
            fun.dimrot1(dxf, v1, p0, 0, dcintf * 3.8, 2, 1.2 * scale, 1.6 * scale, 0.9, "OAL", "", "");
            fun.dimrot1(dxf, p29, p27, 180, dcintf * 2, 2, 1.2 * scale, 1.6 * scale, 0.9, "LS", "", "");
            //fun.dimrot1(dxf, p26, p25, 90, (p26.X - p21.X) / 2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "DN", "", "");
            fun.dimrot1(dxf, p30, p29, -90, dconms, 2, 1.2 * scale, 1.6 * scale, 0.9, "DCONMS", "", "");
            fun.dimrot1(dxf, p8, p11, 90, dcintf, 2, 1.2 * scale, 1.6 * scale, 0.9, "DCINTF", "", "");
            fun.dimrot1(dxf, p19, p15, 90, dcintf * 1.5, 2, 1.2 * scale, 1.6 * scale, 0.9, "DC", "", "");
            fun.dimrot1(dxf, p35, p43, -90, dcintf / 2.5, 2, 1.2 * scale, 1.6 * scale, 0.9, "PHD", "", "");
            fun.Singlelinearrow(dxf, "LF", v24, 180, fun.Polar(v24, 0, dconms / 2.0), fun.Polar(v24, 0, dconms), 1.2 * scale, 1.6 * scale);

            fun.jdbz2(dxf, new Line(p0, fun.Polar(p0, pi / 2, 0.1)), new Line(p0, fun.Polar(p0, pi / -2 - 0.1 * pi / 180, 0.1)), dcintf * 2.5, 1.2 * scale, 1.6 * scale, 0.9, "SIG", "", "");
            /*fun.jdbz2(dxf, new Line(p2, fun.Polar(p2, 0, 0.1)), new Line(p2, p10), dcintf * 3, 1.2 * scale, 1.6 * scale, 0.9, "FHA", "", "");
            
            fun.Singlelinearrow(dxf, "CCMS", p28, 80, fun.Polar(p28, 80 * pi / 180, dconms / 2.0), fun.Polar(p28, 80 * pi / 180, dconms), 1.2 * scale, 1.6 * scale);
            fun.Singlelinearrow(dxf, "FDP", v4, 180, fun.Polar(v4, 0, dconms / 2.0), fun.Polar(v4, 0, dconms), 1.2 * scale, 1.6 * scale);
            fun.Axis(dxf, fun.Polar(p31, pi / -2, oal / 3.0), 0, -90, "Z", "X", "Y", 1, 1.2 * scale, 1);
            fun.Axis(dxf, v1, 0, -90, "", "", "", 0.3 * scale, 1.2 * scale, 1);
            fun.Axis(dxf, v3, 0, -90, "", "", "", 0.3 * scale, 1.2 * scale, 1);
            fun.Axis(dxf, p0, 0, -90, "", "", "", 0.3 * scale, 1.2 * scale, 1);
            */
            Line linev1 = new Line(v5, v6);
            Line linev2 = new Line(v9, v10);
            Line linev3 = new Line(v12, v13);
            Line line4 = new Line(v15, v16);
            Text txt1 = new Text("CIP", v7, 1.2 * scale, 2);
            Text txt2 = new Text("CRP", v11, 1.2 * scale, 2);
            Text txt3 = new Text("MCS", v14, 1.2 * scale, 2);
            Text txt4 = new Text("PCS", v17, 1.2 * scale, 2);

            Circle circle1 = new Circle(Pus.ToV3(v8, 0), 1.7 * 0.3 * scale);
           // dxf.AddEntity(new EntityObject[] { circle1, linev1, txt1, linev2, txt2, linev3, txt3, line4, txt4 });
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

    }
}


